package com.sky.controller.user;

import com.sky.entity.Category;
import com.sky.result.Result;
import com.sky.service.user.UserCategoryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user/category")
@Slf4j
@RequiredArgsConstructor
public class UserCategoryController {
    private final UserCategoryService userCategoryService;

    /**
     * 查询分类
     * @param type
     * @return
     */
    @GetMapping("/list")
    public Result<List<Category>> findAllByType(@RequestParam(required = false) Integer type){
        long l = System.currentTimeMillis();
        log.error("分类：{}",type);
        List<Category> list = userCategoryService.findAll(type);
        log.info("查询耗时：{}ms", System.currentTimeMillis() - l);
        log.info("查询结果：{}", list);
        return Result.success(list);
    }
}
